<?php
$CaptchaExtension = "gif";
function GetChanPostFields($tid,$sage,$txt,$pic,$password,$captcha)
{
	$data = array(
		"task" => "post",
		"name"=>"",
		"link"=>"",
		"nya1"=>"",
		"nya2"=>($sage?"sage":""),
		"nya3"=>"",
		"nya4"=>$txt,
		"file"=>"@".$pic,
		"postredir"=>"0",
		"password"=>$password,
	);
	if ($tid)
		$data['parent']=$tid;
	if ($captcha)
		$data['captcha']=$captcha;		
	return $data;
}
function GetChanDeleteFields($tids,$pass)
{
	$r = "";
	foreach ($tids as $i => $tid)
	{
		$r.="delete={$tid}&";
	}
	return $r."task=delete&password=$pass";
}
function GetChanPostUrl($board)
{
	return "http://iichan.ru/cgi-bin/wakaba.pl/$board";
}
function GetChanDeleteUrl($board)
{
	return "http://iichan.ru/cgi-bin/wakaba.pl/$board";
}
function GetPageUrl($page,$board)
{
	if (!$page)
		return "http://iichan.ru/{$board}/";
	else
		return "http://iichan.ru/{$board}/{$page}.html";
}
function GetChanCaptchaUrl($tid,$board)
{
	if ($tid)
		return "http://iichan.ru/cgi-bin/captcha.pl/{$board}/?key=res{$tid}&dummy={$tid}";
	else
		return "http://iichan.ru/cgi-bin/captcha.pl/{$board}/?key=mainpage&dummy=";
}
function CheckMakePostResult($r)
{
	if (strpos($r['body'],"Вам закрыт доступ к доске. Прощайте.") OR strpos($r['body'],"403 Forbidden"))
	{
		return array(PostResult_Banned,0);
	}
	else if (preg_match("~<html><body><a href=\"/[\w]+/res/[\d]+\.[\w]+\">/[\w]+/res/([\d]+)\.[\w]+\</a></body></html>~",$r['body'],$m) OR preg_match("~Location\: /\w+/res/(\d+)\.html~",$r['header'].$r['body'],$m))
	{
		return array(PostResult_OK,$m[1]);
	}	
	else if (strpos($r['header'].$r['body'],'<a href="/b/wakaba.html">'))
	{
		return array(PostResult_OK,0);
	}
	else if (strpos($r['body'],"пароль"))
	{
		return array(PostResult_WrongPassw,0);
	}
	else if (strpos($r['body'],"уже запощен."))
	{
		return array(PostResult_PicExist,0);
	}
	else if (strpos($r['body'],"тред не существует"))
	{
		return array(PostResult_NoThread,0);
	}
	else if (strpos($r['body'],"неправильный код подтверждения"))
	{
		return array(PostResult_CaptchaWrong,0);
	}
	else if (strpos($r['body'],"код"))
	{
		return array(PostResult_Captcha,0);
	}
	else if (strpos($r['body'],"Ошибка:"))
	{
		return array(PostResult_WakabaErr,0);
	}		
	else
		return array(PostResult_UnknownErr,0);
}
?>